package com.hamizhong.iflowers.web.action.admin.admin;

import net.sf.json.JSONObject;

import com.hamizhong.iflowers.service.IAdminService;
import com.hamizhong.iflowers.utils.MyConstants;
import com.hamizhong.iflowers.web.base.MyBaseAjaxAction;
import com.hamizhong.iflowers.web.dto.IOPResultDto;
import com.hamizhong.iflowers.web.vo.AdminVO;
import com.hamizhong.iflowers.web.vo.IObjectVO;

public class AjaxUpdateAdminPasswordAction extends MyBaseAjaxAction {
	
	private IAdminService iAdminService;
	
	public IAdminService getiAdminService() {
		return iAdminService;
	}
	public void setiAdminService(IAdminService iAdminService) {
		this.iAdminService = iAdminService;
	}
	
	@Override
	protected JSONObject doRequest() {
		logger.info("...invoke...AjaxUpdateOrderStateAction...");
		String adminId = getRQ().getParameter("adminId");
		String oldPassword = getRQ().getParameter("oldPassword");
		String newPassword = getRQ().getParameter("newPassword");
		String newPasswordRe = getRQ().getParameter("newPasswordRe");
		JSONObject jo = new JSONObject();
		if(!newPassword.equals(newPasswordRe)) {
			jo.put("result", MyConstants.AJAX_FAILED_ALERT);
			jo.put("msg", "两次输入的新密码不相同！");
			return jo;
		}
		AdminVO adminVO = new AdminVO();
		adminVO.setAdminId(Integer.valueOf(adminId));
		adminVO.setLoginPassword(oldPassword);
		adminVO.setNewPassword(newPassword);
		adminVO.setNewPasswordRe(newPasswordRe);
		IOPResultDto<IObjectVO> dto = iAdminService.doUpdateAdminPassword(adminVO);
		if(dto.isSuccess()) {
			jo.put("result", MyConstants.AJAX_SUCCESS);
		}else {
			jo.put("result", MyConstants.AJAX_FAILED_ALERT);
			jo.put("msg", dto.getErrorMSG());
		}
		return jo;
	}

}
